<?php

class sqlWorker extends Worker{
	/*
	 * 'host'     => '115.28.48.51', 
	'username' => 'root', 
	'password' => 'p@ssw0rd456', 
	'dbname'   => 'ibmmdm', 
	'prefix'   => 'fn_', 
	'charset'  => 'utf8', 
	'port'     => '',
	 */
	protected $_host;
	
	protected $_username;
	
	protected $_password;
	
	protected $_dbname;
	
	protected $_charset;
	
	protected $_port;
	
	protected $_db       = null;
	
	public function __construct(){
		$configClass       = new Config();
		$this->_host       = $configClass->getKey("database")->getKey("host")->get();
		$this->_username   = $configClass->getKey("database")->getKey("username")->get();
		$this->_password   = $configClass->getKey("database")->getKey("password")->get();
		$this->_dbname     = $configClass->getKey("database")->getKey("dbname")->get();
		$this->_charset    = $configClass->getKey("database")->getKey("charset")->get();
		$this->_port       = $configClass->getKey("database")->getKey("port")->get();
		
		$dsn               = "mysql:host={$this->_host};dbname={$this->_dbname}";
		$this->_db         = new PDO($dsn, $this->_username, $this->_password);
		$this->_db->query("set names ".$this->_charset);			
	}
	
	/**
	 * @message sql
	 */
	public function work($message){		
		if(!$this->_db){
			throw new Exception('$this->_db not defined');
		}		
		$eff = $this->_db->query($message);
		if($this->_db->errorCode() !== '00000'){
			throw new Exception("xxx");		
		}
	}
}
